<?php

	require_once("Client.php");

	class EditClientController{

		var $client;
	
		var $companyOrig;
		var $addressOrig;
		var $cellNoOrig;
		var $telNoOrig;
		var $faxNoOrig;
		var $emailAddOrig;
	
		var $company;
		var $address;
		var $cellNo;
		var $telNo;
		var $faxNo;
		var $emailAdd;
		
		var $flag;
		
		function getClientData(){
			$this->client = $_REQUEST['client'];
					
			$this->companyOrig = $_REQUEST['companyOrig'];
			$this->addressOrig = $_REQUEST['addressOrig'];
			$this->cellNoOrig = $_REQUEST['cellNoOrig'];
			$this->telNoOrig = $_REQUEST['telNoOrig'];
			$this->faxNoOrig = $_REQUEST['faxNoOrig'];
			$this->emailAddOrig = $_REQUEST['emailAddOrig'];
			
			$this->company = $_REQUEST['company'];
			$this->address = $_REQUEST['address'];
			$this->cellNo = $_REQUEST['cellNo'];
			$this->telNo = $_REQUEST['telNo'];
			$this->faxNo = $_REQUEST['faxNo'];
			$this->emailAdd = $_REQUEST['emailAdd'];
			
			$this->flag = $_REQUEST['flag'];
		}

		function retrieveClientInfo($clientToView){
			$client = new Client;
			$client->viewInfo($clientToView);
		}
	}				
//Start of program------------------------------------------------------------------------------
	$editClientController = new EditClientController;
	$editClientController->getClientData();
	
	if($editClientController->flag=="selectClient"){
		$editClientController->retrieveClientInfo($editClientController->client);
	}
	
	elseif($editClientController->flag=="submit"){
			echo "	<script>";

			echo "		client = \"".$editClientController->client."\";";
			
			echo "		company2 = \"".$editClientController->companyOrig."\";";
			echo "		address2 = \"".$editClientController->addressOrig."\";";
			echo "		cellNo2 = \"".$editClientController->cellNoOrig."\";";
			echo "		telNo2 = \"".$editClientController->telNoOrig."\";";
			echo "		faxNo2 = \"".$editClientController->faxNoOrig."\";";
			echo "		emailAdd2 = \"".$editClientController->emailAddOrig."\";";
			
			echo "		company = \"".$editClientController->company."\";";
			echo "		address = \"".$editClientController->address."\";";
			echo "		cellNo = \"".$editClientController->cellNo."\";";
			echo "		telNo = \"".$editClientController->telNo."\";";
			echo "		faxNo = \"".$editClientController->faxNo."\";";
			echo "		emailAdd = \"".$editClientController->emailAdd."\";";
			
			echo "		from = \"confirm\";";
			
			echo "		$.post('viewClientInfo.php',{";
			
			echo "			client: client,";

			echo "			companyOrig: company2,";
			echo "			addressOrig: address2,";
			echo "			cellNoOrig: cellNo2,";
			echo "			telNoOrig: telNo2,";
			echo "			faxNoOrig: faxNo2,";
			echo "			emailAddOrig: emailAdd2,";
			
			echo "			company: company,";
			echo "			address: address,";
			echo "			cellNo: cellNo,";
			echo "			telNo: telNo,";
			echo "			faxNo: faxNo,";
			echo "			emailAdd: emailAdd,";

			echo "			from:from";
			echo "			},function(data){";
			echo "				$('#view').html(data);";
			echo "			}";
			echo "		);";
			echo "	</script>";
	}
	elseif($editClientController->flag=="confirm"){
		$client = new Client();
		$client->sendClientDetails($editClientController->client, $editClientController->company, $editClientController->address, $editClientController->cellNo, $editClientController->telNo, $editClientController->faxNo, $editClientController->emailAdd);
		$client->edit();
	}
?>